 <script>
	import {useCommonStore} from '@/store/common.js';
	import {useUserStore} from '@/store/user.js';
	import {useShopStore} from '@/store/shop.js'
	export default {
		async onLaunch(option) { 
			uni.hideTabBar();//隐藏原生tabbar 
			const commonStore = useCommonStore();
			const userStore  = useUserStore();
			const shopStore  = useShopStore();
			uni.setStorage('checkStatus',0);//初始化检查实名和企业注册的状态，在首页中根据改状态来弹窗提示用户去实名认证/企业注册。
			// 储存设备信息到缓存中
			uni.getSystemInfo({
				success: (res) => {
					commonStore.setSystemInfo(res)
				}
			});
			// #ifdef APP-PLUS
			// 判断用户是否同意隐私政策和协议
			if(!plus.runtime.isAgreePrivacy()){
				this.$mRouter.redirectTo({ route: '/pages/public/agree' })
			}
			plus.screen.lockOrientation("portrait-primary");//锁定屏幕方向，不让横屏
			plus.navigator.closeSplashscreen();//关闭默认的启动屏
			// 创建一个webview 来用作启动页
			let webviewStyles = {}
			if (uni.getSystemInfoSync().platform=='ios') {
				webviewStyles = {
					top: - uni.getSystemInfoSync().safeAreaInsets.top,
					height:uni.getSystemInfoSync().windowHeight+uni.getSystemInfoSync().safeAreaInsets.top+uni.getSystemInfoSync().safeAreaInsets.bottom,
					zindex: 999,
				}
			} else {
				let bottom = uni.getSystemInfoSync().brand =='Xiaomi' ? uni.getSystemInfoSync().safeAreaInsets.top: 0
				webviewStyles = {
					// top: 0,
					height:uni.getSystemInfoSync().windowHeight,
					bottom: - bottom,
					scalable:true,
					zindex: 999
				}
			}
			var w = plus.webview.open(
					'/hybrid/html/advertise/advertise.html',
					101,
					webviewStyles,
					'fade-in', 
					500
			);
			//设置定时器，4s后关闭启动广告页
			setTimeout(function() {
				plus.webview.close(w);
			}, 4000);
			// 如果没有网络
			let network = true
			uni.getNetworkType({
				success: (res) => {
					if (res.networkType == 'none') {
						network = false
					}
				}
			});
			if (!network) {
				await this.$mHelper.getTabbar()
				this.$isResolve()
				return
			}
			// #endif
			// 判断用户是否已登录
			if (uni.getStorageSync('access_token')) {
				// 根据token获取用户信息 并存储用户信息到缓存中
				this.$http.get('api/User/GetUserClaim').then(info=>{
					userStore.updateInfo(info);
				}).catch(err=>{
					userStore.logout()
					uni.redirectTo({
						url: '/'
					});
				});
				// 根据用户来获取店铺列表
				try{
					const res = await this.$http.get('api/User/GetShopsByUser' );
					if (res&&res.length!=0) {
						console.log('APP请求店铺列表成功');
						shopStore.login(res)
						try{
							// 获取店铺未读消息数量
							const msgBadge = await this.$newHttp.get('api/Message/GetUnReadMessageQuantity');
							if(msgBadge.code === 200){
								shopStore.setMsgBadge(msgBadge.data)
							}
						}catch(e){
							//TODO handle the exception
							uni.showToast({
								title:'获取消息失败，错误原因：'+e
							})
						} 
					}else{
						shopStore.setNoShop()
					}
				}catch(e){
					//TODO handle the exception
					console.log('异常抛出：'+e);
				}
			}else{
				// 如果用户token已到期清除缓存
				uni.removeStorageSync('access_token');
				uni.removeStorageSync('user');
				uni.removeStorageSync('shop');
			}
			// // 加载tabbr 
			await this.$mHelper.getTabbar();
			// this.$isResolve();
		},
		onShow: async function() { 
			// console.log('App Show');
			// const shopStore  = useShopStore();
			// let shop = uni.getStorageSync('shop');
			// let user = uni.getStorageSync('user');
			// if(shop&&user){
			// 	shopStore.updateUserMenus(shop.id)
			// 	await this.$mHelper.getTabbar()
			// 	this.$isResolve()
			// }
		},
		onHide: function() {
			console.log('App Hide')
		},
		onReady() {
			uni.hideTabBar();		
		},
		methods: {
		}
	}
</script>
 
<style lang="scss">
	/*每个页面公共css */
	@import '@/style/common.scss';
	 @import "./uni_modules/vk-uview-ui/index.scss";
	page{
		height: 100%;
		background-color: #f7f7f7;
	}
.uni-scroll-view ::-webkit-scrollbar {  
    display: none !important;  
    width: 0 !important;  
    height: 0 !important;  
    -webkit-appearance: none;  
    background: transparent;  
}
/* 全局字体颜色 */
text {
	color: #333333;
	font-size: 30rpx;
}
view {
	color: #333333;
	font-size: 28rpx;
}
/* 全局修改form必填*样式 */
.u-form-item--left__content--required {
	color: #C30D23 !important;
}
.box-color {
	background-color: #FFFFFF;
}
.box-padding {
	padding: 30rpx 35rpx;
}
.box-padding-col {
	padding: 0 35rpx;
}
.bottom-speac {
	margin-bottom: 20rpx;
}
// 全局导航栏icon大小
.header-icon {
	width: 44rpx;
	height: 44rpx;
}
// 全局导航栏占位高度
.status_bar {
	height: var(--status-bar-height);
	width: 100%;
}
// 全局灰盒子
.grey-box {
	// padding: 5rpx 15rpx;
	padding: 0 15rpx;
	height: 50rpx;
	line-height: 50rpx;
	background: #F8F8F8;
	border-radius: 5rpx;
	font-size: 24rpx;
	color:#999999;
	text-align: center;
	// margin-right: 15rpx;
}
.new-grey-box{
	padding: 0 12rpx;
	height: 36rpx;
	line-height:36rpx;
	background: #F8F8F8;
	border-radius: 5rpx;
	font-size: 24rpx;
	color:#999999;
	text-align: center;
}
// 搜索栏和section fix固定
.top-fixed {
	width: 100%;
	position: fixed;
	z-index: 99;
	background-color: #F8F8F8;
}
// 字间距
@for $i from 5 to 20 {
	.u-letter-spacing-#{$i} {
		letter-spacing: $i + rpx;
	}
}
</style>
